﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Windows.Resources;
using System.IO;

namespace Rachmans.Sabang
{
    public class TranslationLoader
    {
        private Dictionary<string, Dictionary<int, string>> _dictTranslations = new Dictionary<string, Dictionary<int, string>>();
        public Dictionary<string, Dictionary<int, string>> DictTranslations { get { return _dictTranslations; } }
        public string Translation { get; set; }

        public TranslationLoader(ref DataSourceLoader dataSourceLoader, string text, string translation)
        {
            StreamResourceInfo xml = Application.GetResourceStream(new Uri(string.Format("/Rachmans.Sabang;component/Translation/{0}.txt", text), UriKind.Relative));
            StreamReader reader = new StreamReader(xml.Stream);
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                //  Parse the line.
                string[] translationInformations = line.Split(new char[] { '|' });
                if (translationInformations.Length == 3)
                {
                    if (!_dictTranslations.ContainsKey(translationInformations[0]))
                    {
                        Dictionary<int, string> ayaTranslation = new Dictionary<int, string>();
                        ayaTranslation.Add(Int32.Parse(translationInformations[1]), translationInformations[2]);
                        _dictTranslations.Add(translationInformations[0], ayaTranslation);
                    }
                    else
                    {
                        _dictTranslations[translationInformations[0]].Add(Int32.Parse(translationInformations[1]), translationInformations[2]);
                    }
                }
            }

            Translation = translation;
        }
    }
}
